﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HA.ModFlow.Domain.DomainLayer
{

    [Serializable]
    public class Recharge : MFBoundary,ICloneable 
    {
        public Recharge(int nrows, int ncolumns, int nlayers, int nPeriods):base(nrows,ncolumns,nlayers,nPeriods)
        {
            this._periods = new List<RechargePeriod>();

            for (int i = 0; i < nPeriods; i++)
            {

                RechargePeriod rp = new RechargePeriod(nrows, ncolumns);

                this._periods.Add(rp);

            }
        }

        List<RechargePeriod> _periods;

        public List<RechargePeriod> Periods
        {
            get { return _periods; }
            set { _periods = value; }
        }

        RECHARGEOPTION _option = RECHARGEOPTION.HIGHESTACTIVECELL;

        public RECHARGEOPTION Option
        {
            get { return _option; }
            set { _option = value; }
        }


        public object Clone()
        {
            Recharge newRecharge = (Recharge)this.MemberwiseClone(); ;
            newRecharge.Periods = new List<RechargePeriod>();
            newRecharge.Periods.AddRange(this.Periods);
  
            return newRecharge;
        }

        public  void OnResetSperiods(int nPeriods)
        {


            if (this.NPeriods == nPeriods)
            {
                return;
            }

            if (this.NPeriods < nPeriods)
            {
                int nSub = nPeriods - this.NPeriods;

                for (int i = 0; i < nSub; i++)
                {
                    this.Periods.Add(new RechargePeriod(this.RCount, this.CCount));
                }
            }

            else
            {
                int nSub = this.NPeriods - nPeriods;
                this.Periods.RemoveRange(nPeriods, nSub);
            }

            this.NPeriods = nPeriods;
        } 

    }


}
